package algorithm.tree.multitree.inorder;

import algorithm.tree.binarytree.base.TreeNode;
import algorithm.tree.multitree.base.MTreeNode;

import java.util.List;
import java.util.function.Consumer;

public class MTreeInorderRecursion {
    public void traverse(MTreeNode node, int sequenceNum, Consumer<MTreeNode> consumer) {
        if (node != null) {
            List<MTreeNode> children = node.getNodeList();
            for (int i = 0; i < sequenceNum; i++) {
                if (sequenceNum < children.size()) {
                    traverse(node.getNodeList().get(i), sequenceNum, consumer);
                }
            }
            consumer.accept(node);
            for (int i = sequenceNum; i < children.size(); i++) {
                traverse(node.getNodeList().get(i), sequenceNum, consumer);
            }
        }
    }
}
